<?php

namespace app\common\model\firm;

use think\Model;


class Product extends Model
{

    

    

    // 表名
    protected $name = 'firm_product';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'images_array'
    ];
    

    public function getImageAttr($value, $data)
    {
        if ($value) {
            return cdnurl($value, true);
        }
        return '';
    }

    public function getImagesArrayAttr($value, $data)
    {
        if (isset($data['images']) && $data['images']) {
            $images = explode(',', $data['images']);
            foreach ($images as &$v) {
                $v = cdnurl($v, true);
            }
            return $images;
        }
        return [];
    }






    public function firm()
    {
        return $this->belongsTo('app\common\model\firm\Firm', 'f_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
